import { http } from '@/utils'

// 发布文章
export const updateArticle = (data, isDraft, isEdit) => {
  return async () => {
    // 异步操作
    if (isEdit) {
      // 编辑
      await http.put(`/mp/articles/${data.id}?draft=${isDraft}`, data)
    } else {
      // 发布
      await http.post(`/mp/articles?draft=${isDraft}`, data)
    }
  }
}

// 获取文章详情
export const getArticleById = (id) => {
  return async () => {
    const res = await http.get(`/mp/articles/${id}`)
    return res.data.data
  }
}
